package demo7_i;
//空接口，是标记接口，表示被克隆

class Money implements Cloneable{//Cloneable 实现了这个接口，就需要重写clone方法，深拷贝
    public double money = 9.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

}

public class Person implements Cloneable{
    public int age;
    public String name;
    public Money m = new Money();

    public Person( String name, int age) {
        this.age = age;
        this.name = name;
    }
    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
        //return super.clone();
        Person tmp = (Person)super.clone();
        tmp.m = (Money) this.m.clone();
        return tmp;
    }
}
